#ifndef _SM4_TEST_H_
#define _SM4_TEST_H_

struct cipher_testvec {
	const char *key;
	const char *iv;
	const char *iv_out;
	const char *ptext;
	const char *ctext;
	unsigned short klen;
	unsigned int len;
};

/*
 * SM4 test vectors taken from the "The SM4 Blockcipher Algorithm And Its
 * Modes Of Operations" draft RFC
 * https://datatracker.ietf.org/doc/draft-ribose-cfrg-sm4
 */

static const struct cipher_testvec sm4_tv_template[] = {
	{
		/* GB/T 32907-2016 Example 1. */
		.key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
		       "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
		.klen = 16,
		.ptext = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
			 "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
		.ctext = "\x68\x1E\xDF\x34\xD2\x06\x96\x5E"
			 "\x86\xB3\xE9\x4F\x53\x6E\x42\x46",
		.len = 16,
	},
	{ /* Last 10 iterations of GB/T 32907-2016 Example 2. */
	  .key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
		 "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
	  .klen = 16,
	  .ptext = "\x99\x4a\xc3\xe7\xc3\x57\x89\x6a"
		   "\x81\xfc\xa8\xe\x38\x3e\xef\x80"
		   "\xb1\x98\xf2\xde\x3f\x4b\xae\xd1"
		   "\xf0\xf1\x30\x4c\x1\x27\x5a\x8f"
		   "\x45\xe1\x39\xb7\xae\xff\x1f\x27"
		   "\xad\x57\x15\xab\x31\x5d\xc\xef"
		   "\x8c\xc8\x80\xbd\x11\x98\xf3\x7b"
		   "\xa2\xdd\x14\x20\xf9\xe8\xbb\x82"
		   "\xf7\x32\xca\x4b\xa8\xf7\xb3\x4d"
		   "\x27\xd1\xcd\xe6\xb6\x65\x5a\x23"
		   "\xc2\xf3\x54\x84\x53\xe3\xb9\x20"
		   "\xa5\x37\x0\xbe\xe7\x7b\x48\xfb"
		   "\x21\x3d\x9e\x48\x1d\x9e\xf5\xbf"
		   "\x77\xd5\xb4\x4a\x53\x71\x94\x7a"
		   "\x88\xa6\x6e\x6\x93\xca\x43\xa5"
		   "\xc4\xf6\xcd\x53\x4b\x7b\x8e\xfe"
		   "\xb4\x28\x7c\x42\x29\x32\x5d\x88"
		   "\xed\xce\x0\x19\xe\x16\x2\x6e"
		   "\x87\xff\x2c\xac\xe8\xe7\xe9\xbf"
		   "\x31\x51\xec\x47\xc3\x51\x83\xc1",
	  .ctext = "\xb1\x98\xf2\xde\x3f\x4b\xae\xd1"
		   "\xf0\xf1\x30\x4c\x1\x27\x5a\x8f"
		   "\x45\xe1\x39\xb7\xae\xff\x1f\x27"
		   "\xad\x57\x15\xab\x31\x5d\xc\xef"
		   "\x8c\xc8\x80\xbd\x11\x98\xf3\x7b"
		   "\xa2\xdd\x14\x20\xf9\xe8\xbb\x82"
		   "\xf7\x32\xca\x4b\xa8\xf7\xb3\x4d"
		   "\x27\xd1\xcd\xe6\xb6\x65\x5a\x23"
		   "\xc2\xf3\x54\x84\x53\xe3\xb9\x20"
		   "\xa5\x37\x0\xbe\xe7\x7b\x48\xfb"
		   "\x21\x3d\x9e\x48\x1d\x9e\xf5\xbf"
		   "\x77\xd5\xb4\x4a\x53\x71\x94\x7a"
		   "\x88\xa6\x6e\x6\x93\xca\x43\xa5"
		   "\xc4\xf6\xcd\x53\x4b\x7b\x8e\xfe"
		   "\xb4\x28\x7c\x42\x29\x32\x5d\x88"
		   "\xed\xce\x0\x19\xe\x16\x2\x6e"
		   "\x87\xff\x2c\xac\xe8\xe7\xe9\xbf"
		   "\x31\x51\xec\x47\xc3\x51\x83\xc1"
		   "\x59\x52\x98\xc7\xc6\xfd\x27\x1f"
		   "\x4\x2\xf8\x4\xc3\x3d\x3f\x66",
	  .len = 160 },
	{
		/* A.2.1.1 SM4-ECB Example 1 */
		.key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
		       "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
		.klen = 16,
		.ptext = "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb"
			 "\xcc\xcc\xcc\xcc\xdd\xdd\xdd\xdd"
			 "\xee\xee\xee\xee\xff\xff\xff\xff"
			 "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb",
		.ctext = "\x5e\xc8\x14\x3d\xe5\x09\xcf\xf7"
			 "\xb5\x17\x9f\x8f\x47\x4b\x86\x19"
			 "\x2f\x1d\x30\x5a\x7f\xb1\x7d\xf9"
			 "\x85\xf8\x1c\x84\x82\x19\x23\x04",
		.len = 32,
	},
	{
		/* A.2.1.2 SM4-ECB Example 2 */
		.key = "\xFE\xDC\xBA\x98\x76\x54\x32\x10"
		       "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
		.klen = 16,
		.ptext = "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb"
			 "\xcc\xcc\xcc\xcc\xdd\xdd\xdd\xdd"
			 "\xee\xee\xee\xee\xff\xff\xff\xff"
			 "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb",
		.ctext = "\xC5\x87\x68\x97\xE4\xA5\x9B\xBB"
			 "\xA7\x2A\x10\xC8\x38\x72\x24\x5B"
			 "\x12\xDD\x90\xBC\x2D\x20\x06\x92"
			 "\xB5\x29\xA4\x15\x5A\xC9\xE6\x00",
		.len = 32,
	}
};

static const struct cipher_testvec sm4_cbc_tv_template[] = {
	{
		/* A.2.2.1 SM4-CBC Example 1 */
		.key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
		       "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
		.klen = 16,
		.ptext = "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb"
			 "\xcc\xcc\xcc\xcc\xdd\xdd\xdd\xdd"
			 "\xee\xee\xee\xee\xff\xff\xff\xff"
			 "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb",
		.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
		      "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
		.iv_out = "\x4C\xB7\x01\x69\x51\x90\x92\x26"
			  "\x97\x9B\x0D\x15\xDC\x6A\x8F\x6D",
		.ctext = "\x78\xEB\xB1\x1C\xC4\x0B\x0A\x48"
			 "\x31\x2A\xAE\xB2\x04\x02\x44\xCB"
			 "\x4C\xB7\x01\x69\x51\x90\x92\x26"
			 "\x97\x9B\x0D\x15\xDC\x6A\x8F\x6D",
		.len = 32,
	},
	{
		/* A.2.2.2 SM4-CBC Example 2 */
		.key = "\xFE\xDC\xBA\x98\x76\x54\x32\x10"
		       "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
		.klen = 16,
		.ptext = "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb"
			 "\xcc\xcc\xcc\xcc\xdd\xdd\xdd\xdd"
			 "\xee\xee\xee\xee\xff\xff\xff\xff"
			 "\xaa\xaa\xaa\xaa\xbb\xbb\xbb\xbb",
		.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
		      "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
		.iv_out = "\x91\xf2\xc1\x47\x91\x1a\x41\x44"
			  "\x66\x5e\x1f\xa1\xd4\x0b\xae\x38",
		.ctext = "\x0d\x3a\x6d\xdc\x2d\x21\xc6\x98"
			 "\x85\x72\x15\x58\x7b\x7b\xb5\x9a"
			 "\x91\xf2\xc1\x47\x91\x1a\x41\x44"
			 "\x66\x5e\x1f\xa1\xd4\x0b\xae\x38",
		.len = 32,
	}
};

static const struct cipher_testvec sm4_ctr_tv_template[] = {
	{
		/* A.2.5.1 SM4-CTR Example 1 */
		.key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
		       "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
		.klen = 16,
		.ptext = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
			 "\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb"
			 "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc"
			 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
			 "\xee\xee\xee\xee\xee\xee\xee\xee"
			 "\xff\xff\xff\xff\xff\xff\xff\xff"
			 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
			 "\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb",
		.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
		      "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
		.iv_out = "\x00\x01\x02\x03\x04\x05\x06\x07"
			  "\x08\x09\x0A\x0B\x0C\x0D\x0E\x13",
		.ctext = "\xac\x32\x36\xcb\x97\x0c\xc2\x07"
			 "\x91\x36\x4c\x39\x5a\x13\x42\xd1"
			 "\xa3\xcb\xc1\x87\x8c\x6f\x30\xcd"
			 "\x07\x4c\xce\x38\x5c\xdd\x70\xc7"
			 "\xf2\x34\xbc\x0e\x24\xc1\x19\x80"
			 "\xfd\x12\x86\x31\x0c\xe3\x7b\x92"
			 "\x6e\x02\xfc\xd0\xfa\xa0\xba\xf3"
			 "\x8b\x29\x33\x85\x1d\x82\x45\x14",
		.len = 64,
	},
	{
		/* A.2.5.2 SM4-CTR Example 2 */
		.key = "\xFE\xDC\xBA\x98\x76\x54\x32\x10"
		       "\x01\x23\x45\x67\x89\xAB\xCD\xEF",
		.klen = 16,
		.ptext = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
			 "\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb"
			 "\xcc\xcc\xcc\xcc\xcc\xcc\xcc\xcc"
			 "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd"
			 "\xee\xee\xee\xee\xee\xee\xee\xee"
			 "\xff\xff\xff\xff\xff\xff\xff\xff"
			 "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
			 "\xbb\xbb\xbb\xbb\xbb\xbb\xbb\xbb",
		.iv = "\x00\x01\x02\x03\x04\x05\x06\x07"
		      "\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F",
		.iv_out = "\x00\x01\x02\x03\x04\x05\x06\x07"
			  "\x08\x09\x0A\x0B\x0C\x0D\x0E\x13",
		.ctext = "\x5d\xcc\xcd\x25\xb9\x5a\xb0\x74"
			 "\x17\xa0\x85\x12\xee\x16\x0e\x2f"
			 "\x8f\x66\x15\x21\xcb\xba\xb4\x4c"
			 "\xc8\x71\x38\x44\x5b\xc2\x9e\x5c"
			 "\x0a\xe0\x29\x72\x05\xd6\x27\x04"
			 "\x17\x3b\x21\x23\x9b\x88\x7f\x6c"
			 "\x8c\xb5\xb8\x00\x91\x7a\x24\x88"
			 "\x28\x4b\xde\x9e\x16\xea\x29\x06",
		.len = 64,
	}
};

#endif